<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #app,
      i {
        width: 800px;
        margin: 100px auto;
        border: 0px solid #000;
        text-align: center;
      }
      table {
        width: 800px;
        height: 40px;
        margin: 0px auto;
        border: 1px solid #000;
        text-align: center;
      }
      tr,
      th,
      td {
        border: 2px solid #000;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <i>欢迎光临_vue开发的收银_水果店</i>
      <table>
        <tr>
          <th>西瓜 7 ￥/斤，折扣 <8折></th>
        </tr>
        <tr>
          <td>请输入你要购买的斤数 <input v-model="num" type="number" /></td>
        </tr>
        <tr>
          <td><button @click="pay">结账买单~</button></td>
        </tr>
        <tr>
          <td>
            结账单:总价 {{theOriginalPrice}}￥元 折后价:{{aDiscount}}￥元
            省了:{{toSaveMoney}}￥元
          </td>
        </tr>
      </table>
    </div>
    <script src="./vue.js"></script>
    <script>
      new Vue({
        el: "#app",
        data: {
          num: "0",
          theOriginalPrice: "0",
          aDiscount: "0",
          toSaveMoney: "0",
        },
        methods: {
          pay() {
            this.theOriginalPrice = this.num * 7;
            this.aDiscount = this.theOriginalPrice * 0.8;
            this.toSaveMoney = this.theOriginalPrice - this.aDiscount;
            this.num = 0;
            this.toSaveMoney = this.toSaveMoney.toFixed(2);
          },
        },
      });
    </script>
  </body>
</html>
